//
//  UIButton-Extension.swift
//  LCYWeiBo
//
//  Created by 李长友 on 16/8/30.
//  Copyright © 2016年 app. All rights reserved.
//

import UIKit

extension UIButton {
    
    convenience init (imageName: String, backgroundImageName: String? = nil, selectedImageName: String? = nil) {
        self.init()
        
        setImage(UIImage(named: imageName), forState: .Normal)
        setImage(UIImage(named: imageName + "_highlighted"), forState: .Highlighted)
        
        if let backgroundImageName = backgroundImageName {
            setBackgroundImage(UIImage(named: backgroundImageName), forState: .Normal)
            setBackgroundImage(UIImage(named: backgroundImageName + "_highlighted"), forState: .Highlighted)
        }
        
        if let selectedImageName = selectedImageName {
            setImage(UIImage(named: selectedImageName), forState: .Selected)
        }
        
        sizeToFit()
    }
}